#include "crect.h"

/**
 * CRect - constructor
 */
template<typename T> CRect<T>::CRect() {
  min = CVector2D<T> (0, 0);
  max = CVector2D<T> (0, 0);
}
//---------------------------------------------------------------------------

/**
 * CRect - constructor, sets rectangle from vectors
 * @param min
 * @param max
 */
template<typename T> CRect<T>::CRect(CVector2D<T> min, CVector2D<T> max) {
  this->min = min;
  this->max = max;
}
//---------------------------------------------------------------------------

/**
 * CRect - constructor, sets rectangle from sizes
 * @param left
 * @param top
 * @param right
 * @param bottom
 */
template<typename T> CRect<T>::CRect(T left, T top, T right, T bottom) {
  min.setX(left);
  min.setY(top);
  max.setX(right);
  max.setY(bottom);
}
//---------------------------------------------------------------------------

/**
 * getLeft - returns min x axis position
 * @return min x axis
 */
template<typename T> T CRect<T>::getLeft() const {
  return min.getX();
}
//---------------------------------------------------------------------------

/**
 * getTop - returns min y axis position
 * @return min y axis
 */
template<typename T> T CRect<T>::getTop() const {
  return min.getY();
}
//---------------------------------------------------------------------------

/**
 * getRight - returns max x axis position
 * @return max x axis
 */
template<typename T> T CRect<T>::getRight() const {
  return max.getX();
}
//---------------------------------------------------------------------------

/**
 * getBottom - returns max y axis position
 * @return max y axis
 */
template<typename T> T CRect<T>::getBottom() const {
  return max.getY();
}
//---------------------------------------------------------------------------

/**
 * getWidth - returns rectangle width
 * @return width
 */
template<typename T> T CRect<T>::getWidth() const {
  return max.getX() - min.getX();
}
//---------------------------------------------------------------------------

/**
 * getHeight - returns rectangle height
 * @return height
 */
template<typename T> T CRect<T>::getHeight() const {
  return max.getY() - min.getY();
}
//---------------------------------------------------------------------------

/**
 * getMin - returns min vector
 * @return min vector
 */
template<typename T> CVector2D<T> CRect<T>::getMin() const {
  return min;
}
//---------------------------------------------------------------------------

/**
 * getMax - returns max vector
 * @return max vector
 */
template<typename T> CVector2D<T> CRect<T>::getMax() const {
  return max;
}
//---------------------------------------------------------------------------

/**
 * setMin - sets min vector
 * @param min
 */
template<typename T> void CRect<T>::setMin(CVector2D<T> min) {
  this->min = min;
}
//---------------------------------------------------------------------------

/**
 * setMax - sets max vector
 * @param max
 */
template<typename T> void CRect<T>::setMax(CVector2D<T> max) {
  this->max = max;
}
//---------------------------------------------------------------------------

/**
 * isPointInRect - returns true if point is in rectangle
 * @param p
 * @return true/false point is/is not in the rectangle
 */
template<typename T> bool CRect<T>::isPointInRect(const CVector2D<T> &p) {
  if (p.getX() < min.getX()) return false;
  if (p.getX() > max.getX()) return false;
  if (p.getY() < min.getY()) return false;
  if (p.getY() > max.getY()) return false;
  return true;
}
//---------------------------------------------------------------------------

/**
 * toString - prints rectangle information to string
 * @return retezec
 */
template<typename T> string CRect<T>::toString() const {

  // Out stream
  ostringstream stream;

  // Print items to stream
  stream << min.toString() << max.toString();
  return stream.str();
}
//---------------------------------------------------------------------------

template class CRect<char>;
template class CRect<short>;
template class CRect<int>;
template class CRect<long>;
template class CRect<unsigned char>;
template class CRect<unsigned short>;
template class CRect<unsigned int>;
template class CRect<unsigned long>;
template class CRect<float>;
template class CRect<double>;
template class CRect<CBigInt>;
template class CRect<CFraction>;
